package com.axt.dbaudit.action.query;

import java.util.List;
import org.apache.struts2.json.annotations.JSON;
import com.axt.dbaudit.bean.query.QueryStmtBean;
import com.axt.dbaudit.model.query.Stmt;
import com.axt.dbaudit.model.query.StmtAlarm;
import com.axt.dbaudit.model.query.StmtDetail;
import com.axt.soa.msg.types.*;

public class QueryStmtAction extends QueryBaseAction {
	private QueryStmtBean stmtBean = new QueryStmtBean();
	private List<Stmt> stmts = null;
	List<StmtDetail> stmtDetails = null;
	List<StmtAlarm> stmtAlarms = null;
	
	@JSON(name="stmts")
	public List<Stmt> getStmts() {
		return stmts;
	}
	
	void setStmts(List<Stmt> stmts) {
		this.stmts = stmts;
	}
	
	@JSON(name="stmtdetails")
	public List<StmtDetail> getStmtDetails() {
		return stmtDetails;
	}
	
	void setStmtDetails(List<StmtDetail> stmtDetails){
		this.stmtDetails = stmtDetails;
	}
	
	@JSON(name="stmtalarms")
	public List<StmtAlarm> getStmtAlarms(){
		return stmtAlarms;
	}
	
	void setStmtAlarms(List<StmtAlarm> stmtAlarms){
		this.stmtAlarms = stmtAlarms;
	}
	
	@JSON(name="totalRows")
	public int getTotalRows() {
		return totalRows;
	}
	
	@JSON(name="queryProgress")
	public String getQueryProgress() {
		return queryProgress;
	}
	
	@JSON(name="queryDate")
	public String getQueryDate() {
		return queryDate;
	}
	
	@JSON(name="errcode")
	public int getErrcode() {
		return errcode;
	}
	
	@JSON(name="errinfo")
	public String getErrinfo() {
		return errinfo;
	}

	/* 语句查询 */
	public String querySessions() {
		
		/* 查询语句索引 */
		stmtBean.queryStmtIndices(serverPath, filters, queryInResult, maxRowNum);
		
		setErrcode(stmtBean.getErrcode());
		setErrinfo(stmtBean.getErrinfo());
		
		return MsgParam.SUCCESS;

	}
	
	public String queryProcess(){
		/* 获取查询进度 */
		stmtBean.queryProcess(serverPath, filters);
		
		setQueryProgress(stmtBean.getQueryProgress());
		setQueryDate(stmtBean.getQueryDate());
		setErrcode(stmtBean.getErrcode());
		setErrinfo(stmtBean.getErrinfo());
		
		return MsgParam.SUCCESS;
	}
	
	public String queryStmtData(){
		/* 查询结果 */
		stmtBean.queryStmts(serverPath, filters);
		setStmts(stmtBean.getStmts());
		setErrcode(stmtBean.getErrcode());
		setErrinfo(stmtBean.getErrinfo());
		
		return MsgParam.SUCCESS;
	}
	
	public String queryStmtDetail(){
		/* 查询语句详细信息  */
		stmtBean.queryStmtDeatil(serverPath, filters);
		setStmtDetails(stmtBean.getStmtDetails());
		setErrcode(stmtBean.getErrcode());
		setErrinfo(stmtBean.getErrinfo());
		
		return MsgParam.SUCCESS;
	}
	
	public String queryStmtAlarm(){
		/* 查询语句报警信息 */
		stmtBean.queryStmtAlarm(serverPath, filters);
		setStmtAlarms(stmtBean.getStmtAlarms());
		setErrcode(stmtBean.getErrcode());
		setErrinfo(stmtBean.getErrinfo());
		
		return MsgParam.SUCCESS;
	}
}
